﻿using System;
using Newtonsoft.Json;

namespace smp.RabbitMq.Strategies
{
    public class BasicResponderStrategy : IResponderStrategy
    {
        #region Implementation of IResponderStrategy

        public object HandleResponse(IResponderHandler handler, Envelope envelope)
        {
            //var responderHandler = (dynamic)handler;
            var messageType = Type.GetType(envelope.MessageType);
            var messageEntity = (dynamic)JsonConvert.DeserializeObject(envelope.Message, messageType);
            InstancesFactory.Log.Debug("Executing responder handler : {0}", handler.GetType());
            return ((dynamic)handler).Respond(messageEntity);
            //return responderHandler.Respond(messageEntity);
            
        }
        
        #endregion
    }
}
